package com.neusoft.training.podcast.mapper;


import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.neusoft.training.podcast.entity.Category;

public interface CategoryMapper {
	
	//插入新的分类
	@Insert("insert into category(categoryName,type,categoryIsDel) value(#{categoryName},#{type},0)")
	void addCatagory(@Param("categoryName") String categoryName,@Param("type") String type);
	
	//删除分类
	@Delete("delete from category where categoryID=#{categoryID}")
	void cleanCategory(@Param("categoryID") Integer catagoryID);
	
	//显示所有分类
	@Select("select * from category where categoryIsDel = 0")
	List<Category> findAllCategories();
	
	@Update("update category set categoryIsDel=1 where categoryID=#{categoryID}")
	void deleteCategory(@Param("categoryID") Integer catagoryID);
	
	//显示所有分类
	@Select("select categoryName from category where categoryIsDel = 0 and categoryID = #{categoryID}")
	String findCategoryIDbyName(@Param("categoryID") Integer catagoryID);
	
	@Select("select * from category where categoryID = #{categoryID}")
	Category findCategoryName(@Param("categoryID") Integer catagoryID);
	
	//author llx
		@Select("select distinct * from category where categoryID in (select categoryID from video where videoID in (select favouriteVedioID from favourite where favouriteUserID =#{userID}))")
		List<Category> findFavouriteCategory(@Param("userID") Integer userID);
		
		@Select("select distinct * from category where categoryID in (select categoryID from video where authorID=#{userID})")
		List<Category> findPersonVideoCategory(@Param("userID") Integer userID);
		
		@Select("select distinct * from category where categoryID in (select categoryID from video where videoID in (select commentVideoID from comment where commentUserID=#{userID}))")
		List<Category> findCommentVideoCategory(@Param("userID") Integer userID);
	
	

}
